﻿namespace ApiLib.Models.Commons;

/// <summary>
/// 类型和值
/// </summary>
public class BaseKeyValue : BaseKeyValue<object>
{
    /// <summary>
    /// 
    /// </summary>
    public BaseKeyValue()
    {
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="key"></param>
    public BaseKeyValue(string key) : base(key)
    {
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="key"></param>
    /// <param name="value"></param>
    public BaseKeyValue(string key, object? value) : base(key, value)
    {
    }

    /// <summary>
    /// 构造
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <returns></returns>
    public static BaseKeyValue<T> Build<T>()
    {
        return new BaseKeyValue<T>();
    }

    /// <summary>
    /// 构造
    /// </summary>
    /// <param name="key"></param>
    /// <typeparam name="T"></typeparam>
    /// <returns></returns>
    public static BaseKeyValue<T> Build<T>(string key)
    {
        return new BaseKeyValue<T>(key);
    }

    /// <summary>
    /// 构造
    /// </summary>
    /// <param name="key"></param>
    /// <param name="value"></param>
    /// <typeparam name="T"></typeparam>
    /// <returns></returns>
    public static BaseKeyValue<T> Build<T>(string key, T? value)
    {
        return new BaseKeyValue<T>(key, value);
    }

    /// <summary>
    /// 构造
    /// </summary>
    /// <returns></returns>
    public static BaseKeyValue Build()
    {
        return new BaseKeyValue();
    }

    /// <summary>
    /// 构造
    /// </summary>
    /// <param name="key"></param>
    /// <returns></returns>
    public static BaseKeyValue Build(string key)
    {
        return new BaseKeyValue(key);
    }

    /// <summary>
    /// 构造
    /// </summary>
    /// <param name="key"></param>
    /// <param name="value"></param>
    /// <returns></returns>
    public static BaseKeyValue Build(string key, object? value)
    {
        return new BaseKeyValue(key, value);
    }
}

/// <summary>
/// 类型和值
/// </summary>
public class BaseKeyValue<T>
{
    /// <summary>
    /// 
    /// </summary>
    public BaseKeyValue()
    {
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="key"></param>
    public BaseKeyValue(string key) : this()
    {
        Key = key;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="key"></param>
    /// <param name="value"></param>
    public BaseKeyValue(string key, T? value) : this(key)
    {
        Value = value;
    }

    /// <summary>
    /// 名称
    /// </summary>
    public string Key { get; set; } = "";

    /// <summary>
    /// 类型
    /// </summary>
    public string Type { get; set; } = "";

    /// <summary>
    /// 值
    /// </summary>
    public T? Value { get; set; }
}